<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单管理系统 - 数字格式化示例</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }

        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 20px;
            border-bottom: 1px solid #eee;
            margin-bottom: 20px;
        }

        h1 {
            font-size: 24px;
            color: #333;
        }

        .stats {
            display: flex;
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            flex: 1;
            background-color: #fff;
            border-radius: 6px;
            padding: 15px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
            border-left: 4px solid #4a6cf7;
        }

        .stat-card.revenue {
            border-left-color: #4caf50;
        }

        .stat-card.orders {
            border-left-color: #2196f3;
        }

        .stat-card.avg-order {
            border-left-color: #ff9800;
        }

        .stat-card h3 {
            font-size: 14px;
            color: #666;
            margin-bottom: 10px;
        }

        .stat-card .value {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }

        .order-table {
            width: 100%;
            border-collapse: collapse;
        }

        .order-table th {
            background-color: #f5f7fa;
            padding: 12px 15px;
            text-align: left;
            font-weight: 600;
            color: #555;
            border-bottom: 1px solid #eee;
        }

        .order-table td {
            padding: 12px 15px;
            border-bottom: 1px solid #eee;
        }

        .order-table tr:hover {
            background-color: #f9fafc;
        }

        .status {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 500;
        }

        .status.completed {
            background-color: #e8f5e9;
            color: #2e7d32;
        }

        .status.pending {
            background-color: #fff8e1;
            color: #f57c00;
        }

        .status.cancelled {
            background-color: #ffebee;
            color: #c62828;
        }

        .order-id {
            font-family: monospace;
            font-weight: 600;
        }

        .currency {
            color: #1e88e5;
            font-weight: 600;
        }

        .date {
            color: #666;
            font-size: 14px;
        }

        .filter-bar {
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
            align-items: center;
        }

        .search-box {
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 250px;
        }

        .filter-select {
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-left: 10px;
        }

        .pagination {
            display: flex;
            justify-content: flex-end;
            margin-top: 20px;
            gap: 5px;
        }

        .pagination button {
            padding: 8px 12px;
            border: 1px solid #ddd;
            background-color: #fff;
            border-radius: 4px;
            cursor: pointer;
        }

        .pagination button.active {
            background-color: #4a6cf7;
            color: white;
            border-color: #4a6cf7;
        }

        .pagination button:hover:not(.active) {
            background-color: #f5f5f5;
        }

        .locale-selector {
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-left: 10px;
        }
    </style>
</head>

<body>
    <div class="container">
        <header>
            <h1>订单管理系统</h1>
            <div>
                <label for="locale-select">数字格式化区域：</label>
                <select id="locale-select" class="locale-selector">
                    <option value="zh-CN">中国 (zh-CN)</option>
                    <option value="en-US">美国 (en-US)</option>
                    <option value="de-DE">德国 (de-DE)</option>
                    <option value="ja-JP">日本 (ja-JP)</option>
                    <option value="en-IN">印度 (en-IN)</option>
                </select>
            </div>
        </header>

        <div class="stats">
            <div class="stat-card revenue">
                <h3>总收入</h3>
                <div class="value" id="total-revenue">¥0</div>
            </div>
            <div class="stat-card orders">
                <h3>订单总数</h3>
                <div class="value" id="total-orders">0</div>
            </div>
            <div class="stat-card avg-order">
                <h3>平均订单金额</h3>
                <div class="value" id="avg-order">¥0</div>
            </div>
        </div>

        <div class="filter-bar">
            <input type="text" class="search-box" placeholder="搜索订单号、客户名称...">
            <div>
                <select class="filter-select">
                    <option value="all">所有状态</option>
                    <option value="completed">已完成</option>
                    <option value="pending">处理中</option>
                    <option value="cancelled">已取消</option>
                </select>
                <select class="filter-select">
                    <option value="all">所有时间</option>
                    <option value="today">今天</option>
                    <option value="week">本周</option>
                    <option value="month">本月</option>
                </select>
            </div>
        </div>

        <table class="order-table">
            <thead>
                <tr>
                    <th>订单号</th>
                    <th>客户</th>
                    <th>日期</th>
                    <th>商品数量</th>
                    <th>订单金额</th>
                    <th>状态</th>
                </tr>
            </thead>
            <tbody id="orders-table-body">
                <!-- 订单数据将通过JavaScript动态生成 -->
            </tbody>
        </table>

        <div class="pagination">
            <button>1</button>
            <button class="active">2</button>
            <button>3</button>
            <button>4</button>
            <button>5</button>
            <button>下一页 &raquo;</button>
        </div>
    </div>

    <script>
        // 格式化数字的函数
        const formatNumber = (num, locale = 'zh-CN') => {
            return num.toLocaleString(locale);
        };

        // 格式化货币的函数
        const formatCurrency = (amount, locale = 'zh-CN', currency = 'CNY') => {
            return new Intl.NumberFormat(locale, {
                style: 'currency',
                currency: currency,
                minimumFractionDigits: 2
            }).format(amount);
        };

        // 模拟订单数据
        const orders = [
            { id: 20230001, customer: '张三', date: '2023-10-15', items: 3, amount: 1299.99, status: 'completed' },
            { id: 20230002, customer: '李四', date: '2023-10-16', items: 1, amount: 4999.00, status: 'completed' },
            { id: 20230003, customer: '王五', date: '2023-10-17', items: 5, amount: 2450.50, status: 'pending' },
            { id: 20230004, customer: '赵六', date: '2023-10-18', items: 2, amount: 899.00, status: 'completed' },
            { id: 20230005, customer: '钱七', date: '2023-10-19', items: 4, amount: 3299.99, status: 'cancelled' },
            { id: 20230006, customer: '孙八', date: '2023-10-20', items: 7, amount: 5699.50, status: 'pending' },
            { id: 20230007, customer: '周九', date: '2023-10-21', items: 1, amount: 7999.00, status: 'completed' },
            { id: 20230008, customer: '吴十', date: '2023-10-22', items: 3, amount: 1599.99, status: 'pending' },
        ];

        // 当前选择的区域设置
        let currentLocale = 'zh-CN';

        // 渲染订单表格
        function renderOrdersTable() {
            const tableBody = document.getElementById('orders-table-body');
            tableBody.innerHTML = '';

            orders.forEach(order => {
                const row = document.createElement('tr');

                // 使用formatNumber格式化订单ID
                const formattedId = formatNumber(order.id, currentLocale);

                // 使用formatNumber格式化商品数量
                const formattedItems = formatNumber(order.items, currentLocale);

                // 使用formatCurrency格式化金额
                const formattedAmount = formatCurrency(order.amount, currentLocale);

                row.innerHTML = `
                    <td><span class="order-id">${formattedId}</span></td>
                    <td>${order.customer}</td>
                    <td><span class="date">${order.date}</span></td>
                    <td>${formattedItems}</td>
                    <td><span class="currency">${formattedAmount}</span></td>
                    <td><span class="status ${order.status}">${getStatusText(order.status)}</span></td>
                `;

                tableBody.appendChild(row);
            });
        }

        // 更新统计数据
        function updateStats() {
            const totalRevenue = orders.reduce((sum, order) => sum + order.amount, 0);
            const totalOrders = orders.length;
            const avgOrder = totalRevenue / totalOrders;

            // 使用formatCurrency格式化总收入和平均订单金额
            document.getElementById('total-revenue').textContent = formatCurrency(totalRevenue, currentLocale);

            // 使用formatNumber格式化订单总数
            document.getElementById('total-orders').textContent = formatNumber(totalOrders, currentLocale);

            // 使用formatCurrency格式化平均订单金额
            document.getElementById('avg-order').textContent = formatCurrency(avgOrder, currentLocale);
        }

        // 获取状态文本
        function getStatusText(status) {
            const statusMap = {
                'completed': '已完成',
                'pending': '处理中',
                'cancelled': '已取消'
            };
            return statusMap[status] || status;
        }

        // 监听区域选择器变化
        document.getElementById('locale-select').addEventListener('change', function () {
            currentLocale = this.value;
            renderOrdersTable();
            updateStats();
        });

        // 初始化页面
        renderOrdersTable();
        updateStats();

        // 控制台示例输出
        console.log('数字格式化示例:');
        console.log(`123456 在 zh-CN 区域格式化为: ${formatNumber(123456, 'zh-CN')}`);
        console.log(`123456 在 en-US 区域格式化为: ${formatNumber(123456, 'en-US')}`);
        console.log(`123456 在 de-DE 区域格式化为: ${formatNumber(123456, 'de-DE')}`);
        console.log(`15675436903 在 zh-CN 区域格式化为: ${formatNumber(15675436903, 'zh-CN')}`);

        console.log('\n货币格式化示例:');
        console.log(`1299.99 在 zh-CN 区域格式化为: ${formatCurrency(1299.99, 'zh-CN', 'CNY')}`);
        console.log(`1299.99 在 en-US 区域格式化为: ${formatCurrency(1299.99, 'en-US', 'USD')}`);
        console.log(`1299.99 在 de-DE 区域格式化为: ${formatCurrency(1299.99, 'de-DE', 'EUR')}`);
    </script>
</body>

</html>